﻿package com.controller;

import java.io.File;
import java.io.IOException;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.entity.Jiajiaolaoshi;
import com.server.JiajiaolaoshiServer;
import com.util.PageBean;
import net.sf.json.JSONObject;
import com.util.db;
import java.sql.SQLException;
import java.sql.*;
@Controller
public class JiajiaolaoshiController {
	@Resource
	private JiajiaolaoshiServer jiajiaolaoshiService;


   
	@RequestMapping("addJiajiaolaoshi.do")
	public String addJiajiaolaoshi(HttpServletRequest request,Jiajiaolaoshi jiajiaolaoshi,HttpSession session) throws SQLException{
		Timestamp time=new Timestamp(System.currentTimeMillis());
		
		jiajiaolaoshi.setAddtime(time.toString().substring(0, 19));
		jiajiaolaoshiService.add(jiajiaolaoshi);
		
		session.setAttribute("backxx", "添加成功");
		session.setAttribute("backurl", request.getHeader("Referer"));
		
		//session.setAttribute("backurl", "jiajiaolaoshiList.do");
		
		return "redirect:postback.jsp";
		//return "redirect:jiajiaolaoshiList.do";
		
		
		
	}
 
//	处理编辑
	@RequestMapping("doUpdateJiajiaolaoshi.do")
	public String doUpdateJiajiaolaoshi(int id,ModelMap map,Jiajiaolaoshi jiajiaolaoshi){
		jiajiaolaoshi=jiajiaolaoshiService.getById(id);
		map.put("jiajiaolaoshi", jiajiaolaoshi);
		return "jiajiaolaoshi_updt";
	}
	
	
	
	
	
//	后台详细
	@RequestMapping("jiajiaolaoshiDetail.do")
	public String jiajiaolaoshiDetail(int id,ModelMap map,Jiajiaolaoshi jiajiaolaoshi){
		jiajiaolaoshi=jiajiaolaoshiService.getById(id);
		map.put("jiajiaolaoshi", jiajiaolaoshi);
		return "jiajiaolaoshi_detail";
	}
//	前台详细
	@RequestMapping("jjlsDetail.do")
	public String jjlsDetail(int id,ModelMap map,Jiajiaolaoshi jiajiaolaoshi){
		jiajiaolaoshi=jiajiaolaoshiService.getById(id);
		map.put("jiajiaolaoshi", jiajiaolaoshi);
		return "jiajiaolaoshidetail";
	}
//	
	@RequestMapping("updateJiajiaolaoshi.do")
	public String updateJiajiaolaoshi(int id,ModelMap map,Jiajiaolaoshi jiajiaolaoshi,HttpServletRequest request,HttpSession session){
		jiajiaolaoshiService.update(jiajiaolaoshi);
		session.setAttribute("backxx", "修改成功");
		session.setAttribute("backurl", request.getHeader("Referer"));
		return "redirect:postback.jsp";
		//String url = request.getHeader("Referer");
		//return "redirect:"+url;
		//return "redirect:jiajiaolaoshiList.do";
	}

//	分页查询
	@RequestMapping("jiajiaolaoshiList.do")
	public String jiajiaolaoshiList(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Jiajiaolaoshi jiajiaolaoshi, String jiaoshixingming, String zhujiaokecheng, String jiaoling, String xueli, String zhaopian, String lianxidianhua, String feiyong1,String feiyong2, String jiaoshijianjie){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 8);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 8);
		
		
		if(jiaoshixingming==null||jiaoshixingming.equals("")){pmap.put("jiaoshixingming", null);}else{pmap.put("jiaoshixingming", jiaoshixingming);}		if(zhujiaokecheng==null||zhujiaokecheng.equals("")){pmap.put("zhujiaokecheng", null);}else{pmap.put("zhujiaokecheng", zhujiaokecheng);}		if(jiaoling==null||jiaoling.equals("")){pmap.put("jiaoling", null);}else{pmap.put("jiaoling", jiaoling);}		if(xueli==null||xueli.equals("")){pmap.put("xueli", null);}else{pmap.put("xueli", xueli);}		if(zhaopian==null||zhaopian.equals("")){pmap.put("zhaopian", null);}else{pmap.put("zhaopian", zhaopian);}		if(lianxidianhua==null||lianxidianhua.equals("")){pmap.put("lianxidianhua", null);}else{pmap.put("lianxidianhua", lianxidianhua);}		if(feiyong1==null||feiyong1.equals("")){pmap.put("feiyong1", null);}else{pmap.put("feiyong1", feiyong1);}		if(feiyong2==null||feiyong2.equals("")){pmap.put("feiyong2", null);}else{pmap.put("feiyong2", feiyong2);}		if(jiaoshijianjie==null||jiaoshijianjie.equals("")){pmap.put("jiaoshijianjie", null);}else{pmap.put("jiaoshijianjie", jiaoshijianjie);}		
		int total=jiajiaolaoshiService.getCount(pmap);
		pageBean.setTotal(total);
		List<Jiajiaolaoshi> list=jiajiaolaoshiService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "jiajiaolaoshi_list";
	}
	
	@RequestMapping("jiajiaolaoshi_yanben1.do")
	public String jiajiaolaoshi_yanben1(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Jiajiaolaoshi jiajiaolaoshi, String jiaoshixingming, String zhujiaokecheng, String jiaoling, String xueli, String zhaopian, String lianxidianhua, String feiyong1,String feiyong2, String jiaoshijianjie){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 8);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 8);
		
		
		if(jiaoshixingming==null||jiaoshixingming.equals("")){pmap.put("jiaoshixingming", null);}else{pmap.put("jiaoshixingming", jiaoshixingming);}		if(zhujiaokecheng==null||zhujiaokecheng.equals("")){pmap.put("zhujiaokecheng", null);}else{pmap.put("zhujiaokecheng", zhujiaokecheng);}		if(jiaoling==null||jiaoling.equals("")){pmap.put("jiaoling", null);}else{pmap.put("jiaoling", jiaoling);}		if(xueli==null||xueli.equals("")){pmap.put("xueli", null);}else{pmap.put("xueli", xueli);}		if(zhaopian==null||zhaopian.equals("")){pmap.put("zhaopian", null);}else{pmap.put("zhaopian", zhaopian);}		if(lianxidianhua==null||lianxidianhua.equals("")){pmap.put("lianxidianhua", null);}else{pmap.put("lianxidianhua", lianxidianhua);}		if(feiyong1==null||feiyong1.equals("")){pmap.put("feiyong1", null);}else{pmap.put("feiyong1", feiyong1);}		if(feiyong2==null||feiyong2.equals("")){pmap.put("feiyong2", null);}else{pmap.put("feiyong2", feiyong2);}		if(jiaoshijianjie==null||jiaoshijianjie.equals("")){pmap.put("jiaoshijianjie", null);}else{pmap.put("jiaoshijianjie", jiaoshijianjie);}		
		int total=jiajiaolaoshiService.getCount(pmap);
		pageBean.setTotal(total);
		List<Jiajiaolaoshi> list=jiajiaolaoshiService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "jiajiaolaoshi_yanben1";
	}
	@RequestMapping("jiajiaolaoshi_yanben2.do")
	public String jiajiaolaoshi_yanben2(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Jiajiaolaoshi jiajiaolaoshi, String jiaoshixingming, String zhujiaokecheng, String jiaoling, String xueli, String zhaopian, String lianxidianhua, String feiyong1,String feiyong2, String jiaoshijianjie){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 8);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 8);
		
		
		if(jiaoshixingming==null||jiaoshixingming.equals("")){pmap.put("jiaoshixingming", null);}else{pmap.put("jiaoshixingming", jiaoshixingming);}		if(zhujiaokecheng==null||zhujiaokecheng.equals("")){pmap.put("zhujiaokecheng", null);}else{pmap.put("zhujiaokecheng", zhujiaokecheng);}		if(jiaoling==null||jiaoling.equals("")){pmap.put("jiaoling", null);}else{pmap.put("jiaoling", jiaoling);}		if(xueli==null||xueli.equals("")){pmap.put("xueli", null);}else{pmap.put("xueli", xueli);}		if(zhaopian==null||zhaopian.equals("")){pmap.put("zhaopian", null);}else{pmap.put("zhaopian", zhaopian);}		if(lianxidianhua==null||lianxidianhua.equals("")){pmap.put("lianxidianhua", null);}else{pmap.put("lianxidianhua", lianxidianhua);}		if(feiyong1==null||feiyong1.equals("")){pmap.put("feiyong1", null);}else{pmap.put("feiyong1", feiyong1);}		if(feiyong2==null||feiyong2.equals("")){pmap.put("feiyong2", null);}else{pmap.put("feiyong2", feiyong2);}		if(jiaoshijianjie==null||jiaoshijianjie.equals("")){pmap.put("jiaoshijianjie", null);}else{pmap.put("jiaoshijianjie", jiaoshijianjie);}		
		int total=jiajiaolaoshiService.getCount(pmap);
		pageBean.setTotal(total);
		List<Jiajiaolaoshi> list=jiajiaolaoshiService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "jiajiaolaoshi_yanben2";
	}
	@RequestMapping("jiajiaolaoshi_yanben3.do")
	public String jiajiaolaoshi_yanben3(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Jiajiaolaoshi jiajiaolaoshi, String jiaoshixingming, String zhujiaokecheng, String jiaoling, String xueli, String zhaopian, String lianxidianhua, String feiyong1,String feiyong2, String jiaoshijianjie){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 8);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 8);
		
		
		if(jiaoshixingming==null||jiaoshixingming.equals("")){pmap.put("jiaoshixingming", null);}else{pmap.put("jiaoshixingming", jiaoshixingming);}		if(zhujiaokecheng==null||zhujiaokecheng.equals("")){pmap.put("zhujiaokecheng", null);}else{pmap.put("zhujiaokecheng", zhujiaokecheng);}		if(jiaoling==null||jiaoling.equals("")){pmap.put("jiaoling", null);}else{pmap.put("jiaoling", jiaoling);}		if(xueli==null||xueli.equals("")){pmap.put("xueli", null);}else{pmap.put("xueli", xueli);}		if(zhaopian==null||zhaopian.equals("")){pmap.put("zhaopian", null);}else{pmap.put("zhaopian", zhaopian);}		if(lianxidianhua==null||lianxidianhua.equals("")){pmap.put("lianxidianhua", null);}else{pmap.put("lianxidianhua", lianxidianhua);}		if(feiyong1==null||feiyong1.equals("")){pmap.put("feiyong1", null);}else{pmap.put("feiyong1", feiyong1);}		if(feiyong2==null||feiyong2.equals("")){pmap.put("feiyong2", null);}else{pmap.put("feiyong2", feiyong2);}		if(jiaoshijianjie==null||jiaoshijianjie.equals("")){pmap.put("jiaoshijianjie", null);}else{pmap.put("jiaoshijianjie", jiaoshijianjie);}		
		int total=jiajiaolaoshiService.getCount(pmap);
		pageBean.setTotal(total);
		List<Jiajiaolaoshi> list=jiajiaolaoshiService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "jiajiaolaoshi_yanben3";
	}
	@RequestMapping("jiajiaolaoshi_yanben4.do")
	public String jiajiaolaoshi_yanben4(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Jiajiaolaoshi jiajiaolaoshi, String jiaoshixingming, String zhujiaokecheng, String jiaoling, String xueli, String zhaopian, String lianxidianhua, String feiyong1,String feiyong2, String jiaoshijianjie){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 8);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 8);
		
		
		if(jiaoshixingming==null||jiaoshixingming.equals("")){pmap.put("jiaoshixingming", null);}else{pmap.put("jiaoshixingming", jiaoshixingming);}		if(zhujiaokecheng==null||zhujiaokecheng.equals("")){pmap.put("zhujiaokecheng", null);}else{pmap.put("zhujiaokecheng", zhujiaokecheng);}		if(jiaoling==null||jiaoling.equals("")){pmap.put("jiaoling", null);}else{pmap.put("jiaoling", jiaoling);}		if(xueli==null||xueli.equals("")){pmap.put("xueli", null);}else{pmap.put("xueli", xueli);}		if(zhaopian==null||zhaopian.equals("")){pmap.put("zhaopian", null);}else{pmap.put("zhaopian", zhaopian);}		if(lianxidianhua==null||lianxidianhua.equals("")){pmap.put("lianxidianhua", null);}else{pmap.put("lianxidianhua", lianxidianhua);}		if(feiyong1==null||feiyong1.equals("")){pmap.put("feiyong1", null);}else{pmap.put("feiyong1", feiyong1);}		if(feiyong2==null||feiyong2.equals("")){pmap.put("feiyong2", null);}else{pmap.put("feiyong2", feiyong2);}		if(jiaoshijianjie==null||jiaoshijianjie.equals("")){pmap.put("jiaoshijianjie", null);}else{pmap.put("jiaoshijianjie", jiaoshijianjie);}		
		int total=jiajiaolaoshiService.getCount(pmap);
		pageBean.setTotal(total);
		List<Jiajiaolaoshi> list=jiajiaolaoshiService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "jiajiaolaoshi_yanben4";
	}
	@RequestMapping("jiajiaolaoshi_yanben5.do")
	public String jiajiaolaoshi_yanben5(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Jiajiaolaoshi jiajiaolaoshi, String jiaoshixingming, String zhujiaokecheng, String jiaoling, String xueli, String zhaopian, String lianxidianhua, String feiyong1,String feiyong2, String jiaoshijianjie){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 8);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 8);
		
		
		if(jiaoshixingming==null||jiaoshixingming.equals("")){pmap.put("jiaoshixingming", null);}else{pmap.put("jiaoshixingming", jiaoshixingming);}		if(zhujiaokecheng==null||zhujiaokecheng.equals("")){pmap.put("zhujiaokecheng", null);}else{pmap.put("zhujiaokecheng", zhujiaokecheng);}		if(jiaoling==null||jiaoling.equals("")){pmap.put("jiaoling", null);}else{pmap.put("jiaoling", jiaoling);}		if(xueli==null||xueli.equals("")){pmap.put("xueli", null);}else{pmap.put("xueli", xueli);}		if(zhaopian==null||zhaopian.equals("")){pmap.put("zhaopian", null);}else{pmap.put("zhaopian", zhaopian);}		if(lianxidianhua==null||lianxidianhua.equals("")){pmap.put("lianxidianhua", null);}else{pmap.put("lianxidianhua", lianxidianhua);}		if(feiyong1==null||feiyong1.equals("")){pmap.put("feiyong1", null);}else{pmap.put("feiyong1", feiyong1);}		if(feiyong2==null||feiyong2.equals("")){pmap.put("feiyong2", null);}else{pmap.put("feiyong2", feiyong2);}		if(jiaoshijianjie==null||jiaoshijianjie.equals("")){pmap.put("jiaoshijianjie", null);}else{pmap.put("jiaoshijianjie", jiaoshijianjie);}		
		int total=jiajiaolaoshiService.getCount(pmap);
		pageBean.setTotal(total);
		List<Jiajiaolaoshi> list=jiajiaolaoshiService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "jiajiaolaoshi_yanben5";
	}
	
	
	
	@RequestMapping("jjlsList.do")
	public String jjlsList(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Jiajiaolaoshi jiajiaolaoshi, String jiaoshixingming, String zhujiaokecheng, String jiaoling, String xueli, String zhaopian, String lianxidianhua, String feiyong1,String feiyong2, String jiaoshijianjie){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 8);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 8);
		
		
		if(jiaoshixingming==null||jiaoshixingming.equals("")){pmap.put("jiaoshixingming", null);}else{pmap.put("jiaoshixingming", jiaoshixingming);}		if(zhujiaokecheng==null||zhujiaokecheng.equals("")){pmap.put("zhujiaokecheng", null);}else{pmap.put("zhujiaokecheng", zhujiaokecheng);}		if(jiaoling==null||jiaoling.equals("")){pmap.put("jiaoling", null);}else{pmap.put("jiaoling", jiaoling);}		if(xueli==null||xueli.equals("")){pmap.put("xueli", null);}else{pmap.put("xueli", xueli);}		if(zhaopian==null||zhaopian.equals("")){pmap.put("zhaopian", null);}else{pmap.put("zhaopian", zhaopian);}		if(lianxidianhua==null||lianxidianhua.equals("")){pmap.put("lianxidianhua", null);}else{pmap.put("lianxidianhua", lianxidianhua);}		if(feiyong1==null||feiyong1.equals("")){pmap.put("feiyong1", null);}else{pmap.put("feiyong1", feiyong1);}		if(feiyong2==null||feiyong2.equals("")){pmap.put("feiyong2", null);}else{pmap.put("feiyong2", feiyong2);}		if(jiaoshijianjie==null||jiaoshijianjie.equals("")){pmap.put("jiaoshijianjie", null);}else{pmap.put("jiaoshijianjie", jiaoshijianjie);}		
		int total=jiajiaolaoshiService.getCount(pmap);
		pageBean.setTotal(total);
		List<Jiajiaolaoshi> list=jiajiaolaoshiService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "jiajiaolaoshilist";
	}
	@RequestMapping("jjlsListtp.do")
	public String jjlsListtp(@RequestParam(value="page",required=false)String page,
			ModelMap map,HttpSession session,Jiajiaolaoshi jiajiaolaoshi, String jiaoshixingming, String zhujiaokecheng, String jiaoling, String xueli, String zhaopian, String lianxidianhua, String feiyong1,String feiyong2, String jiaoshijianjie){
		if(page==null||page.equals("")){
			page="1";
		}
		PageBean pageBean=new PageBean(Integer.parseInt(page), 8);
		Map<String, Object> pmap=new HashMap<String,Object>();
		pmap.put("pageno", pageBean.getStart());
		pmap.put("pageSize", 8);
		
		
		if(jiaoshixingming==null||jiaoshixingming.equals("")){pmap.put("jiaoshixingming", null);}else{pmap.put("jiaoshixingming", jiaoshixingming);}		if(zhujiaokecheng==null||zhujiaokecheng.equals("")){pmap.put("zhujiaokecheng", null);}else{pmap.put("zhujiaokecheng", zhujiaokecheng);}		if(jiaoling==null||jiaoling.equals("")){pmap.put("jiaoling", null);}else{pmap.put("jiaoling", jiaoling);}		if(xueli==null||xueli.equals("")){pmap.put("xueli", null);}else{pmap.put("xueli", xueli);}		if(zhaopian==null||zhaopian.equals("")){pmap.put("zhaopian", null);}else{pmap.put("zhaopian", zhaopian);}		if(lianxidianhua==null||lianxidianhua.equals("")){pmap.put("lianxidianhua", null);}else{pmap.put("lianxidianhua", lianxidianhua);}		if(feiyong1==null||feiyong1.equals("")){pmap.put("feiyong1", null);}else{pmap.put("feiyong1", feiyong1);}		if(feiyong2==null||feiyong2.equals("")){pmap.put("feiyong2", null);}else{pmap.put("feiyong2", feiyong2);}		if(jiaoshijianjie==null||jiaoshijianjie.equals("")){pmap.put("jiaoshijianjie", null);}else{pmap.put("jiaoshijianjie", jiaoshijianjie);}		
		int total=jiajiaolaoshiService.getCount(pmap);
		pageBean.setTotal(total);
		List<Jiajiaolaoshi> list=jiajiaolaoshiService.getByPage(pmap);
		map.put("page", pageBean);
		map.put("list", list);
		session.setAttribute("p", 1);
		return "jiajiaolaoshilisttp";
	}
	
	@RequestMapping("deleteJiajiaolaoshi.do")
	public String deleteJiajiaolaoshi(int id,HttpServletRequest request){
		jiajiaolaoshiService.delete(id);
		String url = request.getHeader("Referer");
		return "redirect:"+url;
		//return "redirect:jiajiaolaoshiList.do";
	}
	
	@RequestMapping("quchongJiajiaolaoshi.do")
	public void quchongJiajiaolaoshi(Jiajiaolaoshi jiajiaolaoshi,HttpServletResponse response){
		   Map<String,Object> map=new HashMap<String,Object>();
		   map.put("lianxidianhua", jiajiaolaoshi.getLianxidianhua());
		   System.out.println("lianxidianhua==="+jiajiaolaoshi.getLianxidianhua());
		   System.out.println("lianxidianhua222==="+jiajiaolaoshiService.quchongJiajiaolaoshi(map));
		   JSONObject obj=new JSONObject();
		   if(jiajiaolaoshiService.quchongJiajiaolaoshi(map)!=null){
				 obj.put("info", "ng");
			   }else{
				   obj.put("info", "联系电话可以用！");
				  
			   }
		   response.setContentType("text/html;charset=utf-8");
		   PrintWriter out=null;
		   try {
			out=response.getWriter();
			out.print(obj);
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			out.close();
		}
	}
}
